#ifndef TETRIS_H
#define TETRIS_H

#include <QWidget>
#include <QImage>
#include "tetrimino.h"
#include <QKeyEvent>

QT_BEGIN_NAMESPACE
namespace Ui { class Tetris; }
QT_END_NAMESPACE

class Tetris : public QWidget
{
    Q_OBJECT

public:
    Tetris(QWidget *parent = nullptr);
    ~Tetris();
    void paintEvent(QPaintEvent *event) override;
    void timerEvent(QTimerEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;

    void drawlines(QPainter &p);
    void drawCurr(QPainter &p);
    void drawNext(QPainter &p);
    void drawStore(QPainter &p);
    void drawBack(QPainter &p);
    void drawScore(QPainter &p);

    void newnext();
    void randnext();

    void down();
    bool candown();
    bool canleft();
    bool canright();

    bool outofbound();
    bool coincidence();
    void rotate();

    void landdown();
    bool fullline(int line);
    void putdownline(int line);
    void clearline();
    void init();

    bool inwall();
    void changestore();


private:
    Ui::Tetris *ui;
    QImage bg;

    QImage Iimg;
    QImage Limg;
    QImage Oimg;
    QImage Jimg;
    QImage Simg;
    QImage Zimg;
    QImage Timg;

    Tetrimino *curr;    //父类类型指向子类对象
    Tetrimino *next;
    Tetrimino *store;
    Tetrimino *temp;

    int tid;

    Cell* wall[20][10];

    int status;
    int score;
    int level;
    int tval;


};
#endif // TETRIS_H
